from boot import QLabel, Union, QWidget, Qt, QPixmap


__all__ = ["QQ9FromTitle", "QQ9QrcodeLabel"]


class QQ9FromTitle(QLabel):

    def __init__(self, parent: Union[QWidget, None]=None, text: str=""):
        super().__init__(parent=parent)

        # 基础设置
        self.setContentsMargins(0, 0, 0, 0)
        self.setAlignment(Qt.AlignCenter)

        self.setText(text)

        # 设置样式
        self._set_style_sheet()

    def _set_style_sheet(self):
        self.setStyleSheet(
            """
            font-family: "微软雅黑";
            font-size: 14px;
            color: #555555;
            background-color: transparent;
            """
        )


class QQ9QrcodeLabel(QLabel):

    def __init__(self, width: int = 75, height: int = 75, parent=None):
        super().__init__(parent=parent)

        self.setFixedSize(width, height)

        self.setAlignment(Qt.AlignCenter)
        self.setContentsMargins(0, 0, 0, 0)
        self.setStyleSheet("""
            QrcodeLabel {
                background-color: transparent;
            }
        """)

    def set_qrcode(self, icon_path: str) -> None:
        pixmap = QPixmap(icon_path)
        scaled_pixmap = pixmap.scaled(self.width(), self.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        self.setPixmap(scaled_pixmap)

